package game.module.item.processor;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import game.common.PlayingRoleMsgProcessor;
import game.entity.PlayingRole;
import game.module.item.bean.Item;
import game.module.item.dao.ItemCache;
import game.module.item.logic.ItemManager;
import lion.common.MsgCodeAnn;
import lion.netty4.message.MyRequestMessage;
import lion.netty4.message.RequestMessageRaw;
import lion.netty4.message.RequestProtoMessage;
import lua.LuaMessageHall.C2SGetBackpack;
import lua.LuaMessageHall.Items;
import lua.LuaMessageHall.S2CBackpackItems;

@MsgCodeAnn(msgcode= C2SGetBackpack.id,accessLimit = 500)
public class GetItemProcessor extends PlayingRoleMsgProcessor{

	private static Logger logger = LoggerFactory.getLogger(GetItemProcessor.class);

	@Override
	public void process(PlayingRole playingRole, RequestMessageRaw requestMessage) throws Exception {
		int playerId = playingRole.getId();
		logger.info("player get backpack items,playerId={}",playerId);
		Map<Integer, Item> items =ItemCache.getInstance().getItemTemplateKey(playerId);
		S2CBackpackItems respMsg = new S2CBackpackItems();
		if(items==null||items.size()<=0) {
			playingRole.writeAndFlush(respMsg.build(playingRole.alloc()));
			return;
		}
		List<Item> list = new ArrayList<>();
		list.addAll(items.values());
		Items[] backpackItems = ItemManager.getInstance().packItems(list);
		respMsg.items = backpackItems; //背包数据
		playingRole.writeAndFlush(respMsg.build(playingRole.alloc()));
	}

	@Override
	public void processProto(PlayingRole playingRole, RequestProtoMessage request) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void processWebsocket(PlayingRole playingRole, MyRequestMessage request) throws Exception {
		// TODO Auto-generated method stub
		
	}
	

}
